using Coding4Fun.Phone.Controls;
using MicroMsg.Common.Event;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class RegByMailStepMain : BasePage
	{
		private EventWatcher mWatcherMailReg;
		private bool bIsMailAddressCorrect;
		private bool bIsMMNameCorrect;
		private ToastPrompt mToastMMNameHint;
		private bool bIsPassWordCorrect;
		internal Grid LayoutRoot;
		internal Grid sencondRoot;
		internal panelTitle2Line panelTitle;
		internal Grid ContentPanel;
		internal TextBlock textBlockMailAddress;
		internal PhoneTextBox textBoxMailAddress;
		internal TextBlock textBlockMMName;
		internal PhoneTextBox textBoxMMName;
		internal TextBlock textBlockPassWord;
		internal WaterMarkPassWordBox textBoxPassWord;
		private bool _contentLoaded;
		public RegByMailStepMain()
		{
			this.InitializeComponent();
			this.mToastMMNameHint = MessageBoxManager.ShowToast("可以使用英文、数字、减号与下划线，最多20个字", 2500, null, false);
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (this.mWatcherMailReg == null)
			{
				this.mWatcherMailReg = new EventWatcher(this, null, new EventHandlerDelegate(this.onMailAuthRegHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_MAILREG_SUCCESS, this.mWatcherMailReg);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_MAILREG_ERR, this.mWatcherMailReg);
			}
		}
		protected override void OnPageOut()
		{
			if (this.mWatcherMailReg != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_MAILREG_SUCCESS, this.mWatcherMailReg);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_MAILREG_ERR, this.mWatcherMailReg);
				this.mWatcherMailReg = null;
			}
		}
		private void onMailAuthRegHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.enableAllControls();
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_MAILREG_SUCCESS)
			{
				PageManager.getInstance().PopAllPages(true);
				base.GoToPage("/Source/UI/LoginViews/RegStepSetUserName.xaml", new LoginKind[]
				{
					new LoginKind(LOGINTYPE.REG_TYPE_MAIL)
				}, true);
				return;
			}
		}
		private void textBoxMailAddressGotFocus(object sender, RoutedEventArgs e)
		{
		}
		private void textBoxMailAddressTextChanged(object sender, RoutedEventArgs e)
		{
			if (ToolFunction.checkIsMailAddress(this.textBoxMailAddress.get_Text()))
			{
				this.bIsMailAddressCorrect = true;
			}
			else
			{
				this.bIsMailAddressCorrect = false;
			}
			this.isAllInputDone();
		}
		private void textBoxMMNameGotFocus(object sender, RoutedEventArgs e)
		{
		}
		private void textBoxMMNameTextChanged(object sender, RoutedEventArgs e)
		{
			if (ToolFunction.checkIsLegalMMName(this.textBoxMMName.get_Text()))
			{
				this.bIsMMNameCorrect = true;
			}
			else
			{
				this.bIsMMNameCorrect = false;
			}
			this.isAllInputDone();
		}
		private void textBoxPassWordTextChanged(object sender, RoutedEventArgs e)
		{
			if (ToolFunction.checkIsLegalPassWord(this.textBoxPassWord.Password))
			{
				this.bIsPassWordCorrect = true;
			}
			else
			{
				this.bIsPassWordCorrect = false;
			}
			this.isAllInputDone();
		}
		private bool isAllInputDone()
		{
			(base.get_ApplicationBar().get_Buttons().get_Item(1) as ApplicationBarIconButton).set_IsEnabled(true);
			return true;
		}
		private void btnPreviousStep_Click(object sender, EventArgs e)
		{
			base.GoBack();
		}
		private void btnNextStep_Click(object sender, EventArgs e)
		{
			this.disableAllControls();
			ServiceCenter.sceneReg.doScene(this.textBoxMMName.get_Text(), this.textBoxPassWord.Password, this.textBoxMailAddress.get_Text());
		}
		private void enableAllControls()
		{
			base.get_ApplicationBar().set_IsVisible(true);
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
			(base.get_ApplicationBar().get_Buttons().get_Item(0) as ApplicationBarIconButton).set_IsEnabled(true);
			(base.get_ApplicationBar().get_Buttons().get_Item(1) as ApplicationBarIconButton).set_IsEnabled(true);
			this.textBoxMailAddress.set_IsEnabled(true);
			this.textBoxMMName.set_IsEnabled(true);
			this.textBoxPassWord.set_IsEnabled(true);
		}
		private void disableAllControls()
		{
			base.get_ApplicationBar().set_IsVisible(false);
			ProcessingCover.getProgressBar(this.LayoutRoot, null, null, false, false, null);
			(base.get_ApplicationBar().get_Buttons().get_Item(0) as ApplicationBarIconButton).set_IsEnabled(false);
			(base.get_ApplicationBar().get_Buttons().get_Item(1) as ApplicationBarIconButton).set_IsEnabled(false);
			this.textBoxMailAddress.set_IsEnabled(false);
			this.textBoxMMName.set_IsEnabled(false);
			this.textBoxPassWord.set_IsEnabled(false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/LoginViews/RegByMailStepMain.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.sencondRoot = (Grid)base.FindName("sencondRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.textBlockMailAddress = (TextBlock)base.FindName("textBlockMailAddress");
			this.textBoxMailAddress = (PhoneTextBox)base.FindName("textBoxMailAddress");
			this.textBlockMMName = (TextBlock)base.FindName("textBlockMMName");
			this.textBoxMMName = (PhoneTextBox)base.FindName("textBoxMMName");
			this.textBlockPassWord = (TextBlock)base.FindName("textBlockPassWord");
			this.textBoxPassWord = (WaterMarkPassWordBox)base.FindName("textBoxPassWord");
		}
	}
}
